package com.sunny;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

public class FileNioRead {

    public static void main(String[] args) {

        String path = "aaa";
        File file = new File(path);
        System.out.println(file.getAbsoluteFile());
        try (FileInputStream fin = new FileInputStream(file)){
            FileChannel fc = fin.getChannel();
            ByteBuffer bb = ByteBuffer.allocate(100);
            int len;
            while ((len=fc.read(bb)) != -1){
                bb.clear();
                byte[] bytes = bb.array();
                System.out.write(bytes);
                System.out.println();

            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

}
